<template>
	<view class="block">
		<h5_header>黑名单</h5_header>
		<view class="list">
			<view class="item" v-for="(item,index) in list">
				<image :src="item.headImage || 'https://oss-shop.cciinet.com/files/MiniProgram/circle_avatar.png'" mode="widthFix"></image>
				<view class="content">
					<view class="info">
						<view class="h1">
							{{item.name || ""}}
						</view>
						<view class="p">
							{{item.companyName || ""}}
						</view>
					</view>
				</view>
				<view class="btn" @click="handleOpenBlock(item.blackUserId)">
					解绑
				</view>
			</view>
		</view>
		<view class="no_list" v-if="list.length==0">暂无数据</view>
		<view class="loading-text" v-if="list.length>10">
			{{loadingType === 0 ? contentText.contentdown : (loadingType === 1 ? contentText.contentrefresh : contentText.contentnomore)}}</view>
	</view>
</template>

<script>
	import { getBlackList } from "@/api/profile/index.js"
	import {
		addBlackList
	} from "@/api/shop/index.js";
	import h5_header from "@/components/h5_header.vue"
	export default {
		components: {
			h5_header
		},
		data() {
			return {
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				},
				loadingType: 0,
				list: [],
				userId:"",
			}
		},
		onLoad() {
			this.userId = uni.getStorageSync("userId")
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.handleGetBlackList()
		},
		onReachBottom() {

		},
		onShow() {
			this.handleGetBlackList()
		},
		methods:{
			handleGetBlackList() {
				getBlackList({userId:uni.getStorageSync("userId")}).then(res=>{
					if(res.code===0) {
						this.list=res.data
					}
				})
			},
			handleOpenBlock(id) {
				addBlackList({blackUserId:id,userId:this.userId,status:1}).then(res=>{
					if(res.code===0) {
						uni.showToast({
							icon:"none",
							title:"解绑成功！"
						})
						this.handleGetBlackList()
					}else{
						uni.showToast({
							icon:"none",
							title:res.msg
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.block {
		.loading-text {
			width: 100%;
			text-align: center;
			font-size: 30upx;
		}
		.no_list{
			display: flex;
			justify-content: center;
			margin-top: 100upx;
		}
		.list {
			.item {
				padding: 0 30upx;
				height: 150upx;
				position: relative;
				display: flex;
				align-items: center;

				image {
					width: 110upx;
					height: 110upx;
				}

				.content {
					display: flex;
					padding-bottom: 31upx;
					border-bottom: 1upx solid #EBEBEB;
					width: 100%;
					margin-left: 16upx;
					margin-top: 12upx;

					.h1 {
						font-size: 28upx;
						color: #333333;
					}

					.p {
						font-size: 26upx;
						color: #999999;
						padding-top: 14upx;
					}
				}

				.btn {
					width: 156upx;
					height: 58upx;
					position: absolute;
					right: 30upx;
					background: linear-gradient(0deg, #FDA033, #FF5A03);
					border-radius: 45upx;
					font-size: 30upx;
					color: #FFFFFF;
					text-align: center;
					line-height: 58upx
				}
			}
		}
	}
</style>
